﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace WebApplication1
{
    public partial class reg : System.Web.UI.Page
    {
        string no = null;
        SqlConnection cnn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
        protected void Page_Load(object sender, EventArgs e)
        {
            cnn.Open();
            SqlCommand cmd = new SqlCommand("select top 1 no from regstr order by no desc", cnn);
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows == false)
                txtno.Text = "100";
            else
            {
                while (dr.Read())
                {
                    no = Convert.ToString(Convert.ToInt32(dr.GetString(0)) + 1);
                    txtno.Text = Convert.ToString(no);
                }
            }
            cnn.Close();
        }
        
        protected void regbtn_Click(object sender, EventArgs e)
        {
            cnn.Open();
            SqlCommand cmd = new SqlCommand("insert into regstr values('" + txtno.Text + "','" + txtfname.Text + "','" + txtuname.Text + "','" + txtpass.Text + "','" + txtcno.Text + "','" + female.Text + "','" + txtmail.Text + "')", cnn);
            SqlCommand cmd1 = new SqlCommand("insert into account(accno,name) values('" + txtno.Text + "','" + txtfname.Text + "')", cnn);
            cmd.ExecuteNonQuery();
            cmd1.ExecuteNonQuery();
            cnn.Close();
            Response.Redirect("log.aspx");
        }
    }
}